﻿#include "TestHoliday.h"
#include "Tools.h"
#include <iostream>

TestHoliday::TestHoliday()
{
}

TestHoliday::~TestHoliday()
{
}

void TestHoliday::TestHolidayDay(int beforeDays)
{
	time_t curTime = Tools::GetCurrentTimeStamp();
	tm rangeEndDayTM = Tools::GetDateTimeFrmStamp(curTime);
	rangeEndDayTM.tm_hour = 9;
	//tm rangeBeginDayTM = Tools::AddDays(rangeEndDayTM, -50);
	CTPTm::HolidayManager pManager;
	for (int i = 0; i < beforeDays; ++i)
	{
		tm tmpDay = Tools::AddDays(rangeEndDayTM, -i);
		time_t tmpStamp = Tools::GetTimeStamp(tmpDay);
		std::string tmpDayStr = Tools::DateTimeStamp2Str(tmpStamp);
		std::cout << tmpDayStr << "星期" << tmpDay.tm_wday;
		if (pManager.IsMarketDay(tmpStamp))
		{
			std::cout << "  是行情日";
		}
		else
		{
			std::cout << "  是非行情日";
		}
		std::cout << std::endl;
	}
}

void TestHoliday::TestWorkTime()
{
	time_t curTime = Tools::GetCurrentTimeStamp();
	tm rangeEndDayTM = Tools::GetDateTimeFrmStamp(curTime);
	CTPTm::HolidayManager pManager;
	rangeEndDayTM.tm_hour = 9;
	
	// 今天的行情时间段测试
	{
		time_t tmpStamp = Tools::GetTimeStamp(rangeEndDayTM); 

		std::string tmpDayStr = Tools::DateTimeStamp2Str(tmpStamp);
		std::cout << tmpDayStr;
		if (pManager.IsMarketTime(tmpStamp))
		{
			std::cout << "  是行情时间段";
		}
		else
		{
			std::cout << "  是非行情时间段";
		}
		std::cout << std::endl;
	}

	// 昨天的行情时间段测试
	{
		tm yesDay = Tools::AddDays(rangeEndDayTM, -1);
		time_t tmpStamp = Tools::GetTimeStamp(yesDay);
		justMarketTime(pManager, tmpStamp);
		
		yesDay.tm_hour = 13;
		tmpStamp = Tools::GetTimeStamp(yesDay);
		justMarketTime(pManager, tmpStamp);

		yesDay.tm_hour = 16;
		tmpStamp = Tools::GetTimeStamp(yesDay);
		justMarketTime(pManager, tmpStamp);

		yesDay.tm_hour = 21;
		tmpStamp = Tools::GetTimeStamp(yesDay);
		justMarketTime(pManager, tmpStamp);
	}
}

void TestHoliday::justMarketTime(CTPTm::HolidayManager &pManager, time_t pStamp)
{
	std::string tmpDayStr = Tools::DateTimeStamp2Str(pStamp);
	std::cout << tmpDayStr;
	if (pManager.IsMarketTime(pStamp))
	{
		std::cout << "  是行情时间段";
	}
	else
	{
		std::cout << "  是非行情时间段";
	}
	std::cout << std::endl;
}
